#ifndef __LOG_H__
#define __LOG_H__

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>


extern uint32_t g_debug_level;
extern int fputc(int ch, FILE *f);
uint32_t bs_writer_printf(char *fmt, ...);
void bs_writer_print_hexdump(void *buf, uint32_t len);

// #define LOGL_ERROR    1
// #define LOGL_WARN     2
// #define LOGL_INFO     3
// #define LOGL_DEBUG    4

#ifdef LOGE
#undef LOGE
#endif

#ifdef LOGW
#undef LOGW
#endif

#ifdef LOGI
#undef LOGI
#endif

#ifdef LOGD
#undef LOGD
#endif

#ifdef LOG_TAG               
#define _LOG_TAG    LOG_TAG
#define LOGE(fmt, ...) \
                do { \
                    if (g_debug_level > 0) \
                        bs_writer_printf("[error] " _LOG_TAG fmt"\r\n", ##__VA_ARGS__); \
                } while(0)

#define LOGW(fmt, ...) \
                do { \
                    if (g_debug_level > 1) \
                        bs_writer_printf("[warn] " _LOG_TAG fmt"\r\n", ##__VA_ARGS__); \
                } while(0)

#define LOGI(fmt, ...) \
                do { \
                    if (g_debug_level > 2) \
                        bs_writer_printf("[info] " _LOG_TAG fmt"\r\n", ##__VA_ARGS__); \
                } while(0)

#define LOGD(fmt, ...) \
                do { \
                    if (g_debug_level > 3) \
                        bs_writer_printf("[debug] " _LOG_TAG fmt"\r\n", ##__VA_ARGS__); \
                } while(0)


#else
#define LOGE(fmt, ...) {}
#define LOGW(fmt, ...) {}
#define LOGI(fmt, ...) {}
#define LOGD(fmt, ...) {}

#endif /* LOG_TAG */


#endif /* __LOG_H__ */
